package kgame5.kgui.kcomp {
import flash.display.Loader;
import flash.display.MovieClip;
import flash.events.Event;
import flash.net.URLRequest;
import flash.text.TextField;

/**
 * @author kk
 * 用来展示图片用的，图片还没加载到就显示"loading"
 * 是在坦克游戏中引入的,展示底图，还可以用来展示很多东西
 * 	tf_name:TextField,
			mc_picC:MovieClip,
			mc_loading:MovieClip;
 */
public class SmartPic {
	private var 
		mc:MovieClip,
			tf_name:TextField,
			mc_picC:MovieClip,
			mc_loading:MovieClip;
			
	private var loader:Loader;
	
	public function SmartPic(p_mc:MovieClip){
		mc=p_mc;
			tf_name=mc.tf_name;
			mc_picC=mc.mc_picC;
			mc_loading=mc.mc_loading;
			
		loader=new Loader();
		loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadOK);
		mc_picC.addChild(loader);
		
		//开始先显示loading
		showLoading();
	}
	
	public function loadPic(picUrl:String,sName:String){
		tf_name.text=sName;
		showLoading();
		
		loader.load(new URLRequest(picUrl));
	}
	public function clear(){
		try{
		loader.close();
		}catch(err:Error ){
		}
		showLoading();
	}
	private function onLoadOK(e:Event){
		showPic();
	}
	
	private function showPic(){
		mc_picC.visible=false;
		mc_loading.visible=false;
		
		mc_picC.visible=true;
		mc_loading.stop();
	}
	
	private function showLoading(){
		mc_picC.visible=false;
		mc_loading.visible=false;
		
		mc_loading.visible=true;
		mc_loading.gotoAndPlay(1);
	}
	
	
}//end of class
}
